import $http from '@/api/request.js'
import store from '@/store/index.js'
import pop from '@/common/pop.js'

class Api {

	async myMoney() {
		try {
			const response = await $http.get({
				url: '/DiyApi/myMoney'
			})
			if (response.code != 200) {
				pop.Toast(response.msg)
				throw new Error(response.msg)
			}
			return response.data
		} catch (error) {
			throw error
		}
	}


	async recharge(money, aesId, aesVerifyCode) {
		const requestData = {
			VeriCode: store.state.bid,
			vId: store.state.vid,
			payType: 1,
			money,
			aesId,
			aesVerifyCode
		}
		try {
			const response = await $http.post({
				url: '/SRA_memberRecharge/recharge',
				data: requestData
			})
			if (response.code != 100) {
				pop.Toast(response.msg)
				throw new Error(response.msg)
			}
			return response.data
		} catch (error) {
			throw error
		}
	}


	async getPreferential(Item) {
		let url;
		let params = {
			vId: store.state.vid,
			couponsId: Item.couponsId, // 优惠卷id
			useIntegral: Item.useIntegral, // 是否使用积分抵扣 1 、0
			express: Item.pageData.express
		}
		if (Item.goods_id) {
			url = '/SRA_simMallApi/getPreferential3'
			params['specs_bind_id'] = Item.specs.specs_bind_id ?? ''
			params['goods_id'] = Item.goods_id
			params['num'] = Item.goods_num
			params['single'] = Item.goods_id && Item.open_group != 1 ? 1 : 0
		} else {
			url = '/SRA_simMallApi/getPreferential2'
			params['carIds'] = Item.car_id
			params['operationId'] = ''
		}
		const response = await $http.get({
			url,
			data: params
		})
		if (response.code != 100) {
			pop.Toast(response.msg)
			throw new Error(response.msg)
		}
		return response.data
	}



	async BrandInfo(brand_id) {
		let url = '/singleSaleApi/getGoodsBrandInfo'
		let params = {
			brand_id
		}
		const response = await $http.post({
			url,
			data: params
		})
		if (response.code !== '100') {
			pop.Toast(response.msg)
			throw new Error(response.msg)
		}
		return response.data
	}

	async getConfig() {
		let url = '/privateTeamApi/getConfig'
		const response = await $http.post({
			url
		})
		if (response.errcode != '100') {
			pop.Toast(response.msg)
			throw new Error(response.msg)
		}
		return response.data
	}

	// 获取支付参数
	async getRechargeAct(params) {
		let url = '/SRA_memberRecharge/getRechargeAct'
		const response = await $http.get({
			url,
			data: params
		})
		if (response.code != '100') return pop.Toast(response.msg)

		return response.data
	}

	// 获取支付信息
	async Joinrecharge(data) {
		let url = '/SRA_memberRecharge/recharge'
		const response = await $http.get({
			url,
			data
		})
		if (response.code != '100') return pop.Toast(response.msg)

		return response.data
	}
	
	
	// 获取微信跳转信息
	async getUserBindInfo(){
		let url = '/weChatStoreApi/getUserBindInfo';
		const response = await $http.post({
			url
		})
		if(response.errcode == '100') return response
		// if (response.errcode != '100') return pop.Toast(response.msg);
		// const result = response.data;
		// return response
	}

}
export default new Api()